﻿#pragma once
#include <vector>
#include <mutex>
struct YCameraData
{
    char name[1024] = { 0 };
    char url[4096] = { 0 };         //摄像机主码流
    char sub_url[4096] = { 0 };     //摄像机辅码流
    char save_path[4096] = { 0 };   //视频录制存放目录
};

class YCameraConfig 
{
public:

    //唯一对象实例 单件模式
    static YCameraConfig* Create()
    {
        static YCameraConfig xc;
        return &xc;
    }
    //插入摄像机 线程安全
    void Push(const YCameraData& data);

    /// <summary>
    /// 获取摄像头
    /// </summary>
    /// <param name="index">摄像头索引 从0开始</param>
    /// <returns>返回空对象，可以判断name为空字符串</returns>
    YCameraData GetCamera(int index);


    /// <summary>
    /// 修改摄像机数据
    /// </summary>
    /// <param name="index"></param>
    /// <param name="data"></param>
    /// <returns></returns>
    bool ModifyCamera(int index, const YCameraData& data);

    bool DelCamera(int index);

    /// <summary>
    /// 获取相机数量
    /// </summary>
    /// <returns>失败返回0</returns>
    int GetCameraCount();

    /// <summary>
    /// 存储配置文件
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    bool Save(const char* path);


    /// <summary>
    /// 读取配置 存入cams_
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    bool Load(const char* path);
private:
    YCameraConfig() {}//构造私有 单件模式
    std::vector<YCameraData> cams_;
    std::mutex mux_;
public:
	~YCameraConfig();
};
